
(function () { 
	Lhs.ui.CreateOrderWindow = function (agrs) {
	var pathimage=Ti.App.Properties.getString('pathimage');
	var platformWidth=Titanium.Platform.displayCaps.platformWidth;//Ti.App.Properties.getInt('platformWidth');
	var platformHeight=Titanium.Platform.displayCaps.platformHeight;//Ti.App.Properties.getInt('platformHeight');
	var Order_kv1=80;
	var Order_kv3=150;
	var Order_kv2=(platformWidth-Order_kv1-Order_kv3)/2;
	var Order_kv4=(platformWidth-Order_kv1-Order_kv3)/2;
	
	
	//Ti.API.info('>>>>>>><<<<<<<<'+agrs.TablesId)
	
	
    var win = Titanium.UI.createWindow({
        id: 'Order',
        title: 'Order',
        fullscreen: true,
       
        //backgroundImage: pathimage+'panel_right.png',
        navBarHidden:true,
       //exitOnClose: true,
        backgroundColor:'#e3e3e3',
        orientationModes:[
	        Titanium.UI.LANDSCAPE_LEFT,
	        Titanium.UI.LANDSCAPE_RIGHT,
		]
    });
    
    var egc = new globals.EventGarbageCollection(win);
    egc.addEventListener('back_'+win.id, function () {
    	Lhs.navGroup.close(win, {
             animated: true
        });
    	Ti.App.fireEvent('TableWindow:LoadTables');
	});
	
	
	var OrderTask=require('controls/OrderTask').CreateOrderTask({
	 	backgroundColor:'Transparent',
        width:Order_kv1,
        height:platformHeight,
        left:0,
        TablesId:agrs.TablesId,
        TableName:agrs.TableName,
        egc:egc,
    })
	win.add(OrderTask);
	
	
	
	var OrderItems=require('controls/OrderItems').CreateOrderItems({
	 	backgroundColor:'Transparent',
        width:Order_kv2,
        height:platformHeight,
        left:OrderTask.width,
        idWinParent:win.id,
        OrderName:agrs.Name,
        TicketId:agrs.TicketId,
        json_Tickets:agrs.json_Tickets,
        TablesId:agrs.TablesId,
        TicketId:agrs.TicketId,
        egc:egc,
    })
	win.add(OrderItems);
	
	
    var ScreenMenuCategories=require('controls/ScreenMenuCategories').CreateScreenMenuCategories({
	 	backgroundColor:'Transparent',
        width:Order_kv3,
        height:platformHeight,
        left:OrderItems.width+OrderTask.width,
        TablesId:agrs.TablesId,
        egc:egc,
    })
	win.add(ScreenMenuCategories);
	
	var ScreenMenuItems=require('controls/ScreenMenuItems').CreateScreenMenuItems({
	 	backgroundColor:'Transparent',
        width:Order_kv4,
        height:platformHeight,
        left:ScreenMenuCategories.width+OrderItems.width+OrderTask.width,
        TablesId:agrs.TablesId,
        egc:egc,
    })
	win.add(ScreenMenuItems);
	
	egc.addEventListener('OrderWindow:Cash', function (e) {
		//Ti.API.info('>>>>>>>'+e.data)
		Lhs.navGroup.open(Lhs.ui.CreateCashWindow({
			data:e.data,
			OrderName:agrs.Name,
		}), 
		{
		    animated: true,
		    navBarHidden:true
		});	
	})
	
	
	// 0839814170
	// removing the event listener does
	win.addEventListener('close', function() {
		//Ti.App.removeEventListener('OrderWindow:ChangeTable');
		//Ti.App.removeEventListener('OrderWindow:Cash');
	});
	
	egc.addEventListener('OrderWindow:ChangeTable', function (e) {
		/*
		var popupwin = require('windows/ChangeTablePopup').CreateChangeTablePopup({
			
		});
		popupwin.open();
		*/
		
		
		Lhs.navGroup.open(Lhs.ui.CreateChangeTablePopup({
				TableId:e.TableId,
				TableName:e.TableName,
		}), 
		{
		    animated: true,
		    navBarHidden:true
		});	
	})
		
	egc.addEventListener('OrderWindow:ChangeTableExcute', function (e) {
		//{TableId_New:TableId_New,TableName_New:TableName_New}
		
		agrs.TablesId=e.TableId_New
		agrs.TableName=e.TableName_New
		agrs.TicketId=e.TicketId_New
		Ti.App.fireEvent('OrderItems:ChangeTableExcute',{TableId_New:e.TableId_New,TableName_New:e.TableName_New,TicketId_New:e.TicketId_New});
		Ti.App.fireEvent('OrderTask:ChangeTableExcute',{TableId_New:e.TableId_New,TableName_New:e.TableName_New,TicketId_New:e.TicketId_New});
		Ti.App.fireEvent('ScreenMenuItems:ChangeTableExcute',{TableId_New:e.TableId_New,TableName_New:e.TableName_New,TicketId_New:e.TicketId_New});
		
		
	})
 	return win;
       
    };
})();